<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('疫情防控用户列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 防控部门
				</div>
				<div class="box-tools pull-right">
				    <a type="button" class="btn btn-box-tool" href="#" onclick="epidemicDept()" title="管理部门"><i class="fa fa-edit"></i></a>
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>

	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
				 
		                <input type="hidden" id="parentId" name="parentId">
						<div class="select-list">
							<ul>
								<li>
									部门ID：<input type="text" id="deptId" name="deptId"/>
								</li>
								<li>
									工号：<input type="text" name="userId"/>
								</li>
								<li>
									姓名：<input type="text" name="loginName"/>
								</li>
								
								
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>

		        <div class="btn-group-sm" id="toolbar" role="group">
		        	<a class="btn btn-success" onclick="addwriteuser()" shiro:hasPermission="epidemic:user:add">
		                <i class="fa fa-plus"></i> 新增
		            </a>
		            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="epidemic:user:remove">
		                <i class="fa fa-remove"></i> 删除
		            </a>
		        </div>

		        <div class="col-sm-12 select-table table-striped">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('epidemic:writeuser:edit')}]];
		var removeFlag = [[${@permission.hasPermi('epidemic:writeuser:remove')}]];
		var types = [[${@dict.getType('yq_permise_type')}]];
		var prefix = ctx + "epidemic/writeuser";

		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 250 });
	     	// 回到顶部绑定
	    	if ($.fn.toTop !== undefined) {
	    		var opt = {
	    			win:$('.ui-layout-center'),
	    			doc:$('.ui-layout-center')
	    		};
	    		$('#scroll-up').toTop(opt);
	    	}
		    queryUserList();
		    queryDeptTree();
		});

		function queryUserList() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        importUrl: prefix + "/importData",
		        importTemplateUrl: prefix + "/importTemplate",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "用户",
		        columns: [{
		            checkbox: true
		        },
				{
					field: 'userDeptId',
					title: 'id',
					visible: false
				},
		        {
		            field: 'userId',
					align: 'center',
		            title: '工号'
		        },
		       
		        {
		            field: 'userName',
		            title: '用户名称',
					align: 'center'
		        },
		        {
		            field: 'deptName',
		            title: '部门',
					align: 'center'
		        },
		        
		        {
		            field: 'phonenumber',
		            title: '手机',
					align: 'center'
		        },
		        {
		        	visible: editFlag == 'hidden' ? false : true,
		        	title: '用户状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
					align: 'center',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.userDeptId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.userDeptId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		}

		/**
		 * 查询疫情防控部门
		 */
		function queryDeptTree()
		{
			var url = ctx + "epidemic/dept/treeData";
			var options = {
		        url: url,
		        expandLevel: 2,
		        onClick : zOnClick
		    };
			$.tree.init(options);

			function zOnClick(event, treeId, treeNode) {
				$("#deptId").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
				$.table.search();
			}
		}

		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});

		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});

		$('#btnRefresh').click(function() {
			queryDeptTree();
		});

		/* 用户管理-部门 */
		function dept() {
			var url = ctx + "epidemic/dept";
			$.modal.openTab("部门管理", url);
		}

		/* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" ></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" ></i> ';
    		}
		}

		/* 用户管理-部门 */
		function epidemicDept() {
			var url = ctx + "epidemic/dept";
			$.modal.openTab("部门管理", url);
		}

		/* 用户管理-新增填报人员 */
		function addwriteuser() {
			var deptId = $("#deptId").val();
			if (typeof deptId === 'undefined' || deptId == null || deptId === '') {
				$.modal.alertWarning("请先选择左侧的叶子节点");
				return false;
			}
			$.ajax({
				type: "post",
				url : prefix + "/yezi?deptId" + deptId,
				data: {
					"deptId": deptId
				},
				success: function(data) {
					if(data.code == 0){
						var url = ctx + "epidemic/writeuser/add?deptId="+deptId;
						$.modal.openTab("新增用户", url);
					}else{
						$.modal.alertWarning("请选择左侧的叶子节点");
						return false;
					}
				}
			});
		}

	</script>
</body>

</html>
